﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace FiveInARow.Components
{
	public class DelegateCommand<T> : ICommand
	{
		#region .ctors

		public DelegateCommand(Action<T> handler)
		{
			_handler = handler;
		}

		#endregion .ctors

		#region Fields

		private Action<T> _handler;

		#endregion Fields

		#region Methods

		public bool CanExecute(object parameter)
		{
			return true;
		}

		public event EventHandler CanExecuteChanged;

		public void Execute(object parameter)
		{
			if (_handler != null)
			{
				_handler((T)parameter);
			}
		}

		public void RaiseCanExecuteChanged()
		{
			if (CanExecuteChanged != null)
			{
				CanExecuteChanged(this, null);
			}
		}

		#endregion Methods
	}
}
